
using Youz.Common.DBUtility;
using Youz.Common.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.Common.DAL
{
    /// <summary>
    /// Sys_SystemWarn Data Class
    /// </summary>
    public partial class Sys_SystemWarnDAL : BaseDAL
    {
		private DbHelperSQL DbHelperSQL = new DbHelperSQL();
        public string TableName = "Sys_SystemWarn";

        public Sys_SystemWarnDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Sys_SystemWarn model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Sys_SystemWarn](");
            strSql.Append("[WarnID],[SystemCode],[WarnTime],[WarnContent],[WarnType]");
            strSql.Append(") values (");
            strSql.Append("@WarnID,@SystemCode,@WarnTime,@WarnContent,@WarnType");
            strSql.Append(")");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@WarnID", model.WarnID),
                    new SqlParameter("@SystemCode", model.SystemCode),
                    new SqlParameter("@WarnTime", model.WarnTime),
                    new SqlParameter("@WarnContent", model.WarnContent),
                    new SqlParameter("@WarnType", model.WarnType)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Sys_SystemWarn model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Sys_SystemWarn] set ");
            strSql.Append("[SystemCode]=@SystemCode,[WarnTime]=@WarnTime,[WarnContent]=@WarnContent,[WarnType]=@WarnType");
            strSql.Append(" where [WarnID]=@WarnID");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@WarnID", model.WarnID),
                    new SqlParameter("@SystemCode", model.SystemCode),
                    new SqlParameter("@WarnTime", model.WarnTime),
                    new SqlParameter("@WarnContent", model.WarnContent),
                    new SqlParameter("@WarnType", model.WarnType)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Guid WarnID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Sys_SystemWarn] ");
            strSql.Append(" where [WarnID]=@WarnID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@WarnID", WarnID)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_SystemWarn Get(Guid WarnID)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Sys_SystemWarn] ");
            strSql.Append(" where [WarnID]=@WarnID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("WarnID", WarnID)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_SystemWarn Get(DataRow row)
        {
            if (row == null) return null;

            Sys_SystemWarn model = new Sys_SystemWarn();
	
            
            if (row["WarnID"] != DBNull.Value)
            {
                model.WarnID = (Guid)row["WarnID"];
            }      
            
            if (row["SystemCode"] != DBNull.Value)
            {
                model.SystemCode = (String)row["SystemCode"];
            }      
            
            if (row["WarnTime"] != DBNull.Value)
            {
                model.WarnTime = (DateTime)row["WarnTime"];
            }      
            
            if (row["WarnContent"] != DBNull.Value)
            {
                model.WarnContent = (String)row["WarnContent"];
            }      
            
            if (row["WarnType"] != DBNull.Value)
            {
                model.WarnType = (String)row["WarnType"];
            }      
            

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select * from [Sys_SystemWarn] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int Top, string sqlWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" *  FROM [Sys_SystemWarn] ");
			
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            if(filedOrder.Trim() != "")
            {
                strSql.Append(" order by " + filedOrder);
            }
			
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [Sys_SystemWarn] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Sys_SystemWarn]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by WarnID desc ", out count, cmdParms);
            total = count;
            return dt;
        }
      #endregion  成员方法
    }
}


  